<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): houfy
  - Date: 2016-11-21 11:20:42
  - Description:
-->
<head>
<title>新增流程</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="<%= request.getContextPath() %>/common/nui/nui.js" type="text/javascript"></script>
    <%
    	String actionFlg = "";
    	if(request.getParameter("actionFlg") != null) {
    		actionFlg = (String)request.getParameter("actionFlg");
    	}
    	
    %>
    <%
    	String id = "";
		if(request.getParameter("id")!=null){
			id = (String)request.getParameter("id");
		}
     %>
</head>
<body>
<form id="processinputForm" method="post">
	<input name="process.id" id="id" class="nui-hidden"/>
	<fieldset style="border:sold 1px #aaa;padding:3px,">
	<legend>基本信息</legend>
	<div style="padding:5px;">
		<table>
			<tr>
				<td style="width:90px;">流程名称：</td>
				<td>
					<input name="process.processname" class="nui-textbox" style="width:450px;" required="true" requiredErrorText="流程名称不能为空！"/>
				</td>
			</tr>
			<tr>
				<td style="width:90px;">流程定义：</td>
				<!-- <td>
					<input name="process.processid" class="nui-textbox" style="width:450px;" required="true" requiredErrorText="流程定义ID不能为空！"/>
				</td> -->
				<td>
					<input id="lookup2" name="process.processid" class="mini-lookup" style="width:450px;" 
       		 		textField="processchname" valueField="processdefid" popupWidth="auto" 
       				 popup="#gridPanel" grid="#datagrid1" multiSelect="false"  
       				 required="true" requiredErrorText="流程定义不能为空！"
  				 	 />
				</td>
			</tr>
			
			<tr>
				<td>流程发起URL:</td>
				<td>
					<input name="process.processurl" class="nui-textbox" style="width:450px;" required="true" requiredErrorText="流程发起URL不能为空！"/>
				</td>
			</tr>
			<tr>
				<td>关联业务名称：</td>
				<td>
					<input name="process.businessname" class="nui-textbox" style="width:450px;" required="true" requiredErrorText="关联业务名称不能为空！"/>
				</td>
			</tr>
			
			
		</table>
	</div>
	</fieldset>
	
	<div style="text-align:center;padding:10px;">
		<a class="nui-button" onclick="onOk" style="width:60px;margin-right:20px">确定</a>
		<a class="nui-button" onclick="onCancel" style="width:60px">取消</a>
	</div>
</form>
<!-- lookup -->
	<div id="gridPanel" class="mini-panel" title="header" iconCls="icon-add" style="width:450px;height:250px;" 
	        showToolbar="true" showCloseButton="true" showHeader="false" bodyStyle="padding:0" borderStyle="border:0" 
	    >
	        <div property="toolbar" style="padding:5px;padding-left:8px;text-align:center;">   
	            <div style="float:left;padding-bottom:2px;">
	                <span>流程定义：</span>                
	                <input id="keyText" class="mini-textbox" style="width:160px;" onenter="onSearchClick"/>
	                <a class="mini-button" onclick="onSearchClick">查询</a>
	                <a class="mini-button" onclick="onClearClick">清除</a>
	            </div>
	            <div style="float:right;padding-bottom:2px;">
	                <a class="mini-button" onclick="onCloseClick">关闭</a>
	            </div>
	            <div style="clear:both;"></div>
	        </div>
	        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
	            borderStyle="border:0" showPageSize="false" showPageIndex="false"
	            url="com.shendong.mis.process.queryWfprocessDefine.biz.ext" 
	        >
	            <div property="columns">
	                <div type="checkcolumn" ></div>
	                <div field="processchname" width="120" headerAlign="center" allowSort="true">流程定义名称</div>    
	                <div field="versionsign" width="120" headerAlign="center" allowSort="true">版本号</div>
	                <div field="createtime" width="120" headerAlign="center" allowSort="true">创建时间</div>
	       		 </div>  
	    	</div>
	</div>

<script type="text/javascript">

	nui.parse();
	var actionFlg = "<%=actionFlg %>";
	var id="<%=id %>";
	var form = new nui.Form("#processinputForm");
	if(actionFlg=="edit")
    	{
    		var json = nui.encode({id:id});
			     //各种监听事件
				   $.ajax({
					     url:"com.shendong.mis.process.queryProcessStartlistbyID.biz.ext",
					     type:'POST',
					     data:json,
				         contentType:'text/json',
				 	     async:false,
				 	     cache:false,
				 	     success:function(text){
				 	     	form.setData(text);
		                   	form.setChanged(false);
		                   	nui.get("id").setValue(text.process.id);
		                   	nui.get("lookup2").setText(text.process.processchname);
				 	     }
				  });	
    	}

		//保存数据
		function saveData(){
	        var form = new nui.Form("#processinputForm");
	        form.setChanged(false);
	        //保存
	        var urlStr = "com.shendong.mis.process.saveProcessStartlist.biz.ext";
	        form.validate();
	        if(form.isValid()==false) return;
	
	        var data = form.getData(false,true);
	        var json = nui.encode(data);
			//alert(json);
	        $.ajax({
	          url:urlStr,
	          type:'POST',
	          data:json,
	          cache:false,
	          contentType:'text/json',
	          success:function(text){
	            var returnJson = nui.decode(text);
	            
	            if(returnJson.resultStr == "success"){
	              nui.get("id").setValue(text.process.id);
	              nui.alert("保存成功！", "系统提示", function(action){
	              	 if(action == "ok" || action == "close"){
	                 	 CloseWindow("ok");
	              	 }
	              });
	              
	            }else{
	              nui.alert("保存失败", "系统提示", function(action){
	                if(action == "ok" || action == "close"){
	                  //CloseWindow("saveFailed");
	                }
	              
	               });
	             }
	           }
	         });
          }

	function CloseWindow(action) {
 		if (action == "close"&&form.isChanged()) {
 			if (confirm("数据被修改了，是否先保存？")) {
 				return false;
 			}
 		}
 		if (window.CloseOwnerWindow) 
			return window.CloseOwnerWindow(action);
 		else window.close();
 	}

	function onOk(e) {
 		saveData();
 	}
 
	function onCancel(e) {
 		CloseWindow("cancel"); 
	}
	
	//流程定义的lookup部分的js代码
	 	//mini.parse();

        var grid = mini.get("datagrid1");
        var keyText = mini.get("keyText");

        grid.load();

        function onSearchClick(e) {
            grid.load({
                key: keyText.value
            });
        }
        function onCloseClick(e) {
            var lookup2 = mini.get("lookup2");
            lookup2.hidePopup();
        }
        function onClearClick(e) {
            var lookup2 = mini.get("lookup2");
            lookup2.deselectAll();
        }
	
	
</script>
</body>
</html>